package com.fengye.algorithms.leecode;

/**
 * @Author fengye
 * @Date 2023/4/8 9:45
 **/
public class MaxArea11 {
    public static int maxArea(int[] height) {
        if(height.length <= 1 ){
            return 0;
        }
        int max = 0;
        int left = 0;
        int right = height.length - 1;
        while (left < right) {
            int h = Math.min(height[left], height[right]);
            int l = right - left;
            max = Math.max(max, h * l);
            // 高度比当前大的才有机会比大小
            while (height[left] <= h && left < right) {
                left++;
            }
            while (height[right] <= h && left < right) {
                right--;
            }
        }

        return max;
    }
}
